package com.maoxs;

import com.sun.deploy.util.StringUtils;
import org.apache.commons.io.FileUtils;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.Arrays;

import static com.github.tomakehurst.wiremock.client.WireMock.*;

public class MockServer {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        configureFor(8000);
        removeAllMappings();
        mock("/order/1", "01");
//        mock("/order/2", "02");
        System.out.println("服务部署完毕");

    }

    private static void mock(String url, String file) throws IOException {
        ClassPathResource resource = new ClassPathResource("response/" + file + ".json");
        String content = StringUtils.join(Arrays.asList(FileUtils.readLines(resource.getFile(), "UTF-8").toArray()), "\n");
        stubFor(get(urlPathEqualTo(url)).willReturn(aResponse().withBody(content).withStatus(200)));
    }

}